﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace FunctionMonitor
{
    public class TestUseCase
    {
        private static readonly object _lock1 = new object();
        private static readonly object _lock2 = new object();
        public static void Test()
        {
            var task1 = TaskMonitor.Run(() =>
            {
                lock (_lock1)
                {
                    Thread.Sleep(500);
                    lock (_lock2)
                    {
                        Debug.WriteLine(" deal lock2 ");
                    }
                }

            });

            var task2 = TaskMonitor.FactoryStartNewMonitor(() =>
            {
                lock (_lock2)
                {
                    Thread.Sleep(500);
                    lock (_lock1)
                    {
                        Debug.WriteLine(" deal lock1 ");
                    }
                }
            });

            Task.WaitAll(task1, task2);
        }
    }
}
